import { getAddressList } from "@mall/api/address"
import router from "@src/router";
Component({
  data: {
    hiddenOperate: true,
    addressMsgId: null,
    operateText: { first: '删除地址', second: '设为默认收货地址', thirdly: '取消' },
    addressList: [],
    //给子组件的当前选中对象
    tempAddress: null
  },
  methods: {
    onLoad: function (options) {
    },
    onShow() {
      this.getAddressFunc()
    },
    //获取地址列表
    getAddressFunc() {
      getAddressList().then(res => {
        if (res.code === 0) {
          this.setData({
            addressList: res.data
          })
        } else {
          wx.showToast({
            title: res.msg
          })
        }
      })
    },
    //打开地址操作弹框
    showOperateAddress(e) {
      console.log('e', e)
      this.setData({
        hiddenOperate: false,
        tempAddress: e.currentTarget.dataset.addressobj
      })
    },
    //监听弹框并刷新列表
    refreshList() {
      this.getAddressFunc()
    },
    //跳到新增地址页面
    addAddress() {
      router.push({name: "mall/address-form", params: {mode: 'add'}})
    },
  }
})
